package edu.cmu.cs.stage3.alice.authoringtool.viewcontroller;

import edu.cmu.cs.stage3.alice.authoringtool.AuthoringToolResources;
import edu.cmu.cs.stage3.util.Enumerable;

/**
 * @author Jason Pratt
 */
public class EnumerablePropertyViewController extends PropertyViewController {
	protected javax.swing.JLabel enuerableLabel = new javax.swing.JLabel();
	protected Class valueClass;

	public void set( edu.cmu.cs.stage3.alice.core.Property property, boolean allowExpressions, boolean omitPropertyName, final edu.cmu.cs.stage3.alice.authoringtool.util.PopupItemFactory factory ) {
		super.set( property, true, allowExpressions, false, omitPropertyName, factory );
		this.valueClass = edu.cmu.cs.stage3.alice.authoringtool.util.PopupMenuUtilities.getDesiredValueClass(property);
		if( ! Enumerable.class.isAssignableFrom( this.valueClass ) ) {
			throw new IllegalArgumentException( "valueClass of property " + property + " is not an Enumerable; instead: " + valueClass );
		}
		setPopupEnabled( true );
		refreshGUI();
	}

	//Rem @Override
	protected java.awt.Component getNativeComponent() {
		return enuerableLabel;
	}

	//Rem @Override
	protected Class getNativeClass() {
		return Enumerable.class;
	}

	//Rem @Override
	protected void updateNativeComponent() {
		String text = AuthoringToolResources.getReprForValue( property.get(), property );
		enuerableLabel.setText( text );
	}
}
